See Original text in context
multi sub trait_mod:<is>(Routine , :!)
When a routine is modified with this trait, its return value will be writable. This is useful when returning variables or writable elements of hashes or arrays, for example:
sub walk(\thing, *) is rwmy ;walk(, 'some', 'key', 1, 2) = 'autovivified';say .raku;
produces
("some" => ).hash
Note that return
marks return values as read only; if you need an early exit from an is rw
routine, you have to use return-rw
instead.
See Original text in context
sub trait_mod:<is>(Mu , :!)
The trait is rw
on a class will create writable accessor methods on all public attributes of that class.
is rw;my = C.new.a = 42;say ; # OUTPUT: «42»
See Original text in context
multi sub trait_mod:<is> (Attribute , :!)
Marks an attribute as read/write as opposed to the default readonly
. The default accessor for the attribute will return a writable value.
;my = Boo.new;.bar = 42; # works.baz = 42;CATCH ;# OUTPUT: «X::Assignment::RO: Cannot modify an immutable Any»